# Maintainer: David Runge <dvzrv@archlinux.org>

_name=py-zopfli
pkgname=python-zopfli
pkgver=0.2.3
pkgrel=1
pkgdesc="Python bindings to zopfli"
arch=(loong64 x86_64)
url="https://github.com/fonttools/py-zopfli"
license=(Apache)
depends=(
  glibc
  python
  zopfli libzopfli.so libzopflipng.so
)
makedepends=(
  python-build
  python-installer
  python-setuptools
  python-setuptools-scm
  python-wheel
)
checkdepends=(python-pytest)
source=($_name-$pkgver.tar.gz::$url/archive/refs/tags/v$pkgver.tar.gz)
sha512sums=('071e897270a5af893670a3744d5bec9557cc80ea3ad29dd7bf44e990e8db8a9d1eaa6b8e8bfab38094cfba00d18ee3ff393f729aa95242a52bdfac3535097efb')
b2sums=('c6c352a3ac81b3b5097da038502f73c51778ad0914a8f9e4a3a8fdd7d0ebfc3523fbad87d6527981b3607f898a43f0455f4dd9ac7cd37db9fd80d8a39c76e743')

build() {
  cd $_name-$pkgver
  SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver USE_SYSTEM_ZOPFLI=true python -m build --wheel --no-isolation
}

check() {
  local _site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $_name-$pkgver
  python -m installer --destdir=test_dir dist/*.whl
  export PYTHONPATH="test_dir/$_site_packages:$PYTHONPATH"
  pytest -vv
}

package() {
  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 README.rst -t "$pkgdir/usr/share/doc/$pkgname/"
}
